<?php

// [ 智能BP ]

namespace app\common\lib;
use think\Db;
use think\Session;
use app\common\lib\Cpdf;

class Bp
{
    public static function run($title = '', $imgArr = [])
    {
        if ( empty($imgArr) ) return false;

        // 生成评估报告
        $res  = Cpdf::run($imgArr,'L');

        if (!$res['result']) return false;

        // 写入记录
        $data['member_id']   = Session::get('member.id');
        $data['title']       = $title;
        $data['bp_uri']      = $res['uri'];
        $data['create_time'] = time();
        $num = Db::name('bp')->insert($data);
        if ($num > 0) {
            return [
                'title' => $title,
                'uri'   => $res['uri'],
            ];
        } else {
            return false;
        }
    }
}